var inorderVue = new Vue({
	el : '#inorderPageDiv',
	data : {
		currentPage : 1,
		pageSize : 5,
		totalSize : 10,
		queryBtn : false,
		chooseFileBtn : false,
		labelPosition : 'right',
		orderVo : {
			toWhereHouse : '',
			toWherePosition : '',
			toWhereLocation : '',
			inorderNum : '',
			goodsName : '',
			sku : '',
			pageNum : '',
			pageSize : ''
			
		},
		house: [],
		position : [],
		location : [],
		inorderDetail : [],
		
		uploadUrl : COMMON_URL.URL + 'uploadControlle/uploadFileForInorder',
		fileList : [],
		batUploadFormVisible : false,
		tip1 : '只能上传是 xls(97-2003工作表) 格式文件!',
		tip2 : '文件大小不能超过10MB!',
		tip : '只能上传是 xls(97-2003工作表)格式文件,且文件大小不能超过10MB!',
		dialogFormVisible: false,
		formLabelWidth : '120px',
		createInorderForm : {
			goodsName : '',
			goodsSku : '',
			goodsDesc : '',
			goodsNum :'',
			goodsUnit : '',
			goodsPrice : '',
			goodsProduceDate : '',
			goodsPeriod : '',
			supplierName : '',
			toWhereHouse: '',
			toWhereHouseName : '',
			toWherePosition : '',
			toWherePositionName : '',
			toWhereLocation : '',
			toWhereLocationName : ''
		},
		inorderGoodsDetail : {},
		inorderGoodsData : [],
		orderRules : {
			toWhereHouse :[
				{ required: true, message: '请选择仓库', trigger: 'blur' }
			],
			toWherePosition :[
				{ required: true, message: '请选择库位', trigger: 'blur' }
			],
			toWhereLocation : [
				{ required: true, message: '请选择货位', trigger: 'blur' }
			],
			goodsName : [
				{ required: true, message: '请输入商品名称', trigger: 'blur' },
			    {min : 1, max : 10,message:'需要在1~10个字符或文字之间'}
			],
			goodsSku : [
				{ required: true, message: '请输入商品编码', trigger: 'blur' },
			    {min : 1, max : 25,message:'需要在1~25个字符或文字之间'}
			],
			goodsDesc : [
				{ required: true, message: '请输入商品描述', trigger: 'blur' },
			    {min : 1, max : 15,message:'需要在1~15个字符或文字之间'}
			],
			goodsNum : [
				{ required: true, message: '请输入商品数量', type:'number',trigger: 'blur' }
			],
			goodsPrice : [
				{ required: true, message: '请输入商品价格', type:'number',trigger: 'blur' }
			],
			goodsUnit : [
				{ required: true, message: '请输入商品单位', trigger: 'blur' },
			    {min : 1, max : 3,message:'需要在1~3个字符或文字之间'}
			]
			}
		
	},
	mounted(){
		this.selectHouseForQuery();
		this.selectLocationForQuery();
	},
	methods : {
		beforeUpload(file){
			this.chooseFileBtn = true;
			const extension1 = file.name.split('.')[1] === 'xls';
			const isLt2M = file.size / 1024 / 1024 < 12;
			if(!extension1){
				this.$notify({
		            title: '警告',
		            message: this.tip1,
		            type: 'warning'
		          });
			}
			
			if(!isLt2M){
				this.$notify({
		            title: '警告',
		            message: this.tip2,
		            type: 'warning'
		          });
			}
			
			return extension1 && isLt2M;
			
		},
		uploadSuccess(response, file, fileList){
			this.chooseFileBtn = false;
		},
		selectHouseForQuery(){
			$.ajax({
				url : COMMON_URL.URL + 'housAndPositionController/getAllHouse',
				dataType : 'json',
				type : 'get',
				success : function(data){
					
					if(data.ok){
						inorderVue.house = data.data;
					}else{
						swal(data.msg,'','warning');
					}
					
				},
				error : function(data){
					swal('查询仓库失败','','error');
				}
			});
		},
		selectQueryPositionByHouse(val){
			
			
			if(val == null || val == ''){
				return;
			}
			
			$.ajax({
				url : COMMON_URL.URL + 'housAndPositionController/findPositionForQuery',
				dataType : 'json',
				type : 'get',
				data : {'houseId' : val},
				success : function(data){
					
					if(data.ok){
						inorderVue.position = data.data;
					}else{
						swal(data.msg,'','warning');
					}
				},
				error : function(data){
					swal('查询库位失败','','error');
				}
			});
			
		},
		selectLocationForQuery(){
			$.ajax({
				url : COMMON_URL.URL + "goodsLocationController/getGoodLocation",
				dataType : 'json',
				type : 'get',
				success : function(data){
					
					if(data.ok){
						inorderVue.location = data.data;
					}else{
						swal(data.msg,'','warning');
					}
					
				},
				error : function(data){
					swal('查询失败','','error');
				}
			});
		},
		handleCurrentChange(val){
			this.currentPage = val;
		},
		handleSizeChange(val){
			this.pageSize = val;
		},
		selectOrderHouseForQuery(val){
			if(val == null || val == ''){
				return;
			}
			
			let obj = {};
			obj = this.house.find((item)=>{
				return item.id === val;
			});
			
			this.createInorderForm.toWhereHouseName = obj.houseName;
			this.selectQueryPositionByHouse(val);
		},
		selectOrderPositionForQuery(val){
			if(val == null || val == ''){
				return;
			}
			
			let obj = {};
			obj = this.position.find((item)=>{
				return item.id === val;
			});
			
			this.createInorderForm.toWherePositionName = obj.positionName;
		},
		selectOrderLocationForQuery(val){
			if(val == null || val == ''){
				return;
			}
			
			let obj = {};
			obj = this.location.find((item)=>{
				return item.id === val;
			});
			this.createInorderForm.toWhereLocationName = obj.locationName;
		},
		onQueryForBtn(){
			
			this.orderVo.pageNum = this.currentPage;
			this.orderVo.pageSize = this.pageSize;
			
			this.queryBtn = true;
			
			$.ajax({
				url : COMMON_URL.URL + 'orderManage/queryInorderDetail',
				type : 'post',
				contentType : 'application/json',
				data : JSON.stringify(inorderVue.orderVo),
				success : function(data){
					inorderVue.queryBtn = false;
					if(data.ok){
						inorderVue.inorderDetail = data.data;
					}else{
						swal(data.msg,'','warning');
					}
					
				},
				error : function(data){
					swal('查询失败','','error');
				}
			});
			
		},
		restDialogForm(id){
			this.dialogFormVisible = false;
			this.$refs[id].resetFields();
		},
		submitFomr(formName){
			this.dialogFormVisible = false;
			this.$refs[formName].validate((valid)=>{
				if(valid){
					$.ajax({
						url : COMMON_URL.URL + 'orderManage/saveInorderForOne',
						type : 'POST',
						contentType : 'application/json',
						data : JSON.stringify(inorderVue.createInorderForm),
						success : function(data){
							
							if(data.ok){
							}else{
								swal(data.msg,'','warning');
							}
						},
						error : function(data){
							swal('执行新增失败，请重新输入','','error');
						}
						
					});
				}
			});
			this.$refs[id].resetFields();
		},
		seeGoodsDetail(row){
			var inorderNum = row.inorderNum;
			//根据订单查询物资
			$.ajax({
				url : COMMON_URL.URL + 'orderManage/inorderGoodsDetail',
				type : 'get',
				dataType : 'json',
				data : {
					'inorderNum' : inorderNum
				},
				success : function(data){
					
					if(data.ok){
						inorderVue.inorderGoodsData = data.data;
					}else{
						swal(data.msg,'','warning');
					}
				},
				error : function(data){
					swal('查询订单物料信息失败','','error');
				}
			});
		},
		closePopper(){
			$('#welcome_to_jk').trigger('click');
		},
		statusFormat(row,column){
			var status = row[column.property];
			 if (status == undefined) {  
	             return "状态异常";  
	          } 
			 
			 if(status == 1){
				 return "入库完成";
			 }
			 if(status == 0){
				 return "待审核";
			 }
		},
		dateFormat(row,column){
			
			var date = row[column.property];  
	          if (date == undefined) {  
	             return "";  
	          }  
	          
	          date = new Date(date);
	          return formatDate(date, "yyyy-MM-dd hh:mm");
			
		}
		
	}
});